class WorkreportsController < ApplicationController 
	before_filter :login_required
	
  # GET /workreports
  def index
		@projects = @current_user.projects.find_all_by_closed(false)
  end

  # GET /workreports/1
  def show
    @workreport = Workreport.find(params[:id])
  end

  # GET /workreports/new
  def new
		@project = current_user.projects.find(params[:id])
		@reportable_tasks = @project.tasks.find_all_by_finished(false)
		@workreport = Workreport.new

    respond_to do |format|
      format.html # new.html.erb
    end
  end

  # GET /workreports/1/edit
  def edit
    @workreport = Workreport.find(params[:id])
  end

  # POST /workreports
  def create
    @workreport = Workreport.new(params[:workreport])

    respond_to do |format|
      if @workreport.save
        flash[:notice] = 'Workreport was successfully created.'
        format.html { redirect_to(@workreport) }
      else
        format.html { render :action => "new" }
       end
    end
  end

  # PUT /workreports/1
  def update
    @workreport = Workreport.find(params[:id])

    respond_to do |format|
      if @workreport.update_attributes(params[:workreport])
        flash[:notice] = 'Workreport was successfully updated.'
        format.html { redirect_to(@workreport) }
      else
        format.html { render :action => "edit" }
      end
    end
  end

  # DELETE /workreports/1
  def destroy
		@workreport = Workreport.find(params[:id])
		@workreport.destroy
		flash[:notice] = 'Workreport was successfully deleted.'
		respond_to do |format|
			format.html { redirect_to(workreports_url) }
		end
  end
end
